let Users = require('./../../model/users');


let create = async function(ctx, next) {
    let body = ctx.request.body;
    let users = new Users();
    let code = '';
    let data = '';
    let msg = '';
    await users.findMobile(body.mobile, (error, cb)=> {
        if (error) {
            sess.mongoError(ctx, next, error)
        } else {
            if (!cb) { // null 查询后数据库无该数据，便可新建
                users = new Users({
                    username: body.username, // 可以为空
                    password: body.password, // 必填
                    mobile: body.mobile // 必填
                })
                users.save((error)=> {
                    if (error) {
                        ctx.body = new resModel.Server();
                    } else {
                        ctx.body = new resModel.Success('创建成功');
                    }
                })
            } else { // 该账号已存在
                ctx.body = new resModel.Exist('该账号已存在')
            }
        }
    })
}


module.exports = {
    create
}